package activity.addCamera.adapter;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hichip.campro.R;

import java.util.List;

/**
 * Created by lt on 2017\12\21 0021.
 */

public class WiFiListAdapter extends BaseAdapter {
    private Context context;
    private List<ScanResult> scanResults;

    public WiFiListAdapter(Context context, List<ScanResult> scanResults) {
        this.context=context;
        this.scanResults=scanResults;
    }

    @Override
    public int getCount() {
        return scanResults.size();
    }

    @Override
    public Object getItem(int position) {
        return scanResults.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ScanResult scanResult=scanResults.get(position);
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=View.inflate(context, R.layout.item_wifi_list,null);
            holder.tv_wifi_ssid=convertView.findViewById(R.id.tv_wifi_ssid);
            holder.iv_wifi_lock=convertView.findViewById(R.id.iv_wifi_lock);
            holder.iv_wifi_signal=convertView.findViewById(R.id.iv_wifi_signal);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_wifi_ssid.setText(scanResult.SSID);
        return convertView;
    }
    private class ViewHolder{
        TextView  tv_wifi_ssid;
        ImageView iv_wifi_lock;
        ImageView iv_wifi_signal;
    }
}







